package com.ruoyi.ewem.controller;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.ruoyi.ewem.domain.Outinfo;
import com.ruoyi.ewem.service.OutinfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 出库记录Controller
 *
 * @author ruoyi
 * @date 2024-07-27
 */
@RestController
@RequestMapping("/outinfo")
public class OutinfoController extends BaseController {
    @Autowired
    private OutinfoService outinfoService;

    /**
     * 查询出库记录列表
     */
    @RequiresPermissions("ewem:outinfo:list")
    @GetMapping("/list")
    public TableDataInfo list(Outinfo outinfo) {
        startPage();
        List<Outinfo> list = outinfoService.selectOutinfoList(outinfo);
        return getDataTable(list);
    }

    /**
     * 导出出库记录列表
     */
    @RequiresPermissions("ewem:outinfo:export")
    @Log(title = "出库记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Outinfo outinfo) {
        List<Outinfo> list = outinfoService.selectOutinfoList(outinfo);
        ExcelUtil<Outinfo> util = new ExcelUtil<Outinfo>(Outinfo.class);
        util.exportExcel(response, list, "出库记录数据");
    }

    /**
     * 获取出库记录详细信息
     */
    @RequiresPermissions("ewem:outinfo:query")
    @GetMapping(value = "/{outinfoId}")
    public AjaxResult getInfo(@PathVariable("outinfoId") Long outinfoId) {
        return success(outinfoService.getById(outinfoId));
    }

    /**
     * 新增出库记录
     */
    @RequiresPermissions("ewem:outinfo:add")
    @Log(title = "出库记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Outinfo outinfo) {
        return toAjax(outinfoService.save(outinfo));
    }

    /**
     * 修改出库记录
     */
    @RequiresPermissions("ewem:outinfo:edit")
    @Log(title = "出库记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Outinfo outinfo) {
        return toAjax(outinfoService.updateById(outinfo));
    }

    /**
     * 删除出库记录
     */
    @RequiresPermissions("ewem:outinfo:remove")
    @Log(title = "出库记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{outinfoIds}")
    public AjaxResult remove(@PathVariable Long[] outinfoIds) {
        return toAjax(outinfoService.removeBatchByIds(Arrays.asList(outinfoIds)));
    }
}
